<?php
/**
 * Created by PhpStorm.
 * User: xsp
 * Date: 2018/5/14
 * Time: 14:46
 */

namespace console\controllers;

use yii\console\Controller;

class RbacController extends Controller
{

    /**
     *权限初始化
     */
    public function actionInit()
    {
        $trans = \Yii::$app->db->beginTransaction();
        //下面是查找权限节点的一些方法
        $dir = dirname(dirname(dirname(__FILE__))).'/backend/controllers/';
        $controllers = glob($dir.'*.php');
        foreach ($controllers as $file)
        {
            $content = file_get_contents($file);
            $pattern = '/class ([a-zA-Z]+)Controller/';
            preg_match($pattern,$content,$match);
            $premissions [] = strtolower($match[1].'/*');
            $preg = '/public function action([A-Z][A-Za-z_]+)\(\)/';
            preg_match_all($preg,$content,$matchs);
            foreach ($matchs[1] as  $role){
                $premissions[] = strtolower($match[1].'/'.$role);
            }

        }
        try{


        }catch (\Exception $e)
        {

        }
    }

    public function actionRule()
    {


    }

}